//
//  BCAdItemViewController.m
//  BCVersion
//
//  Created by ZhaoXiang on 2/27/14.
//  Copyright (c) 2014 Jungle. All rights reserved.
//

#import "BCAdItemViewController.h"
#import "UIImageView+WebCache.h"
#import "BCLoginViewController.h"

@interface BCAdItemViewController ()
@property (nonatomic, strong) NSString* title;
@property (nonatomic, strong) NSString* message;
@property (nonatomic, strong) NSString* imageUrl;
@property (nonatomic, assign) CGSize size;
@end



@implementation BCAdItemViewController

- (instancetype)initWithTitle:(NSString*)title message:(NSString*)message imageUrl:(NSString*)imageUrl size:(CGSize)size
{
    self = [super init];
    if (self) {
        self.title = title;
        self.message = message;
        self.imageUrl = imageUrl;
        self.size = size;
    }
    return self;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.frame = CGRectMake(0, 0, self.size.width, self.size.height);
    
    UIImageView* imageView = [[UIImageView alloc] init];
    imageView.frame = self.view.frame;
    
    [imageView setImageWithURL:[NSURL URLWithString:self.imageUrl]];
    
    [self.view addSubview:imageView];

    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonPressed:)]];
    
}




- (void)buttonPressed:(UIView*)sender
{
    [BCLoginViewController checkLoggedInWithBlock:^(BOOL isLoggedIn) {
        if (isLoggedIn) {
                [[[UIAlertView alloc] initWithTitle:self.title message:self.message delegate:Nil cancelButtonTitle:@"确定" otherButtonTitles: nil] show];
        }
    }];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
